<template>
	<view class="mine-container">
		<!-- 用户信息区域 -->
		<view class="user-info">
			<view class="info-content">
				<u-avatar
					:src="userInfo.avatar"
					size="80"
				></u-avatar>
				<view class="user-detail">
					<text class="nickname">{{userInfo.username}}</text>
				</view>
			</view>
			<u-icon name="setting" color="#999" size="28" @click="toEditUserInfoPage"></u-icon>
		</view>
		
		<!-- 功能区域 -->
		<view class="feature-box">
			<view class="feature-item">
				<view class="feature-icon">
					<u-icon name="coupon" size="32" color="#2979ff"></u-icon>
				</view>
				<text class="feature-text">我的优惠券</text>
				<view class="feature-right">
					<u-icon name="arrow-right" color="#999" size="28"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo: {
				avatar: '',
				nickname: ''
			},
			userId: 0
		}
	},
	onLoad() {
		this.getUserInfo()
	},
	// 添加 onShow 生命周期函数
	onShow() {
		// 每次页面显示时重新获取用户信息
		this.getUserInfo()
	},
	methods: {
		// 获取用户信息
		getUserInfo() {
			let that = this
			uni.request({
				url: getApp().globalData().API + '/user/getUserInfo',
				data: {
					userId: that.userId
				},
				success(res) {
					that.userInfo = res.data.data
					that.userId = that.userInfo.userId
				}
			})
		},
		toEditUserInfoPage(){
			uni.navigateTo({
				url: '/pages/edituserinfo/edituserinfo'
			})
		}
	}
}
</script>

<style lang="scss">
.mine-container {
	min-height: 100vh;
	background-color: #f5f5f5;
	
	.user-info {
		background-color: #fff;
		padding: 32rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 20rpx;
		
		.info-content {
			display: flex;
			align-items: center;
			flex: 1;
			margin-right: 20rpx;
			
			.user-detail {
				margin-left: 24rpx;
				flex: 1;
				
				.nickname {
					font-size: 36rpx;
					color: #000;
					font-weight: 400;
					display: block;
				}
			}
		}
	}
	
	.feature-box {
		background-color: #fff;
		padding: 0 32rpx;
		margin-top: 20rpx;
		
		.feature-item {
			display: flex;
			align-items: center;
			padding: 32rpx 0;
			border-bottom: 1rpx solid #eee;
			
			.feature-icon {
				margin-right: 24rpx;
			}
			
			.feature-text {
				flex: 1;
				font-size: 30rpx;
				color: #000;
			}
			
			.feature-right {
				display: flex;
				align-items: center;
				
				.count {
					font-size: 26rpx;
					color: #999;
					margin-right: 12rpx;
				}
			}
		}
	}
	
	.popup-content {
		padding: 30rpx;
		
		.popup-title {
			text-align: center;
			font-size: 32rpx;
			font-weight: bold;
			margin-bottom: 30rpx;
		}
		
		.popup-body {
			padding: 20rpx 0;
		}
	}
}
</style>
